<%-- 
    Document   : vieworders
    Created on : Jan 19, 2013, 4:34:15 AM
    Author     : KAKAIT
--%>

<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.ArrayList"%>
<%@page import="model.ProductImp"%>
<%@page import="model.entity.Product"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.util.List"%>
<%@page import="model.entity.BillDetail"%>
<%@page import="model.BillImp"%>
<%@page import="model.entity.Bill"%>
<%@page import="model.entity.Account"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<div class="col-main" id="ves-col-main">
					
    <script type="text/javascript">
    //&lt;![CDATA[
        window.document.title ="View Order";
    //]]&gt;
    </script>												
						<!-- main content -->
    <%
    String datepurchase = request.getParameter("datepurchase");
    String billid = request.getParameter("billid");
    Account ac = (Account)session.getAttribute("acc");
    BillImp bi = new BillImp();
    List<BillDetail> bdt = bi.ListBillDetail(billid);
    List<Product> lpro = new ArrayList<Product>();
    ProductImp pi = new ProductImp();
    for(int i = 0; i< bdt.size();i++)
    {
        lpro = pi.listProductshoppingcart(bdt.get(i).getProductid(), bdt.get(i).getQuantity());
    }
    session.setAttribute("shoppingcart", lpro);
%>	
<div class="my-account"><div class="page-title title-buttons">
    <h1>Order #<%= billid %> - Pending</h1>
    
    <a class="link-reorder" href="<c:url value="/shoppingcart"/>">Reorder</a>
    <span class="separator">|</span>
    <a class="link-print" href="<c:url value="<%= "/views/user/print_order.jsp" %>"><c:param name="billid" value="<%= billid %>"/><c:param name="datepurchase" value="<%= datepurchase %>"/></c:url>">Print Order</a>
</div>
<dl class="order-info">
    <dt>About This Order:</dt>
    <dd>
                <ul id="order-info-tabs">
                                    <li class="current first last">Order Information</li>
                            </ul>
        <script type="text/javascript">decorateGeneric($('order-info-tabs').select('LI'),['first','last']);</script>
    </dd>
</dl>
<%
    SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
    Date date = formater.parse(datepurchase);
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.MEDIUM);
    
%>
<p class="order-date">Order Date: <%= df.format(date.getTime()) %></p>
    <div class="col2-set order-info-box">
    <div class="col-1">
        <div class="box">
            <div class="box-title">
                <h2>Billing Address</h2>
            </div>
            <div class="box-content">
                <address><%= ac.getFirstname() +" "+ ac.getLastname() %><br>
                    <%= ac.getStreet() %><br>
                    <%= ac.getCity() %> <%= ac.getState_province().toString()!= null ? ac.getState_province() : "" %><br>
                    <%= ac.getCountry() %>.<br>
                    T: <%= ac.getMobile() %><br>
                </address>
            </div>
        </div>
    </div>
    <div class="col-2">
        <div class="box box-payment">
            <div class="box-title">
                <h2>Payment Method</h2>
            </div>
            <div class="box-content">
                <p>Check / Money order</p>
            </div>
        </div>
    </div>
    <div class="col-2">
        <div class="box">
            <div class="box-title">
                <h2>Shipping Method</h2>
            </div>
            <div class="box-content">
                Flat Rate - Fixed 
            </div>
        </div>
    </div>
</div>
                
<div class="order-items order-details">
            <h2 class="table-caption">Items Ordered            </h2>

    <table summary="Items Ordered" id="my-orders-table" class="data-table">
        <colgroup>
            <col width="1">
            <col>
            <col width="1">
            <col width="1">
            <col width="1">
        </colgroup>
        <thead>
            <tr class="first last">
                <th>Product Image</th>
                <th>Product Name</th>
                <th class="a-right">Price</th>
                <th class="a-center">Qty</th>
                <th class="a-right">Subtotal</th>
            </tr>
        </thead>
        
        <tbody class="odd">
            <% 
                double grand_Total = 0;
                for(int i = 0;i < bdt.size();i++)
                {
                    Product pro = pi.DetailProduct(bdt.get(i).getProductid());
                    double money = pro.getTotalamount() * bdt.get(i).getQuantity();
                    grand_Total += money;
            %>
            
            <tr id="order-item-row-2" class="border first last">
                <td><a class="product-image" title="<%= pro.getProductname() %>" href="#"><img width="150" height="150" alt="" src="images/product/<%= pro.getPicture().toString() %>"></a></td>
                <td><h3 class="product-name"><%= pro.getProductname() %></h3></td>
                <td class="a-right">
                                    <span class="cart-price"><span class="price">$<%= Double.toString(pro.getTotalamount()) %></span></span>
                            </td>
                <td class="a-center sct-quantity">
                                <span class="cart-price"><span class="price"><%= bdt.get(i).getQuantity() %></span></span>
                                
                </td>
                <td class="a-right sct-price">
                                <span class="cart-price"><span class="price">$<%= Double.toString(money) %></span></span>
                </td>
    <!--
        <th class="a-right"><span class="price">$999.00</span></th>
            -->
            </tr>
            
            <%}%>
        </tbody>
        <tfoot>
            <tr class="subtotal first">
            <td class="a-righttfoot" colspan="4">
                            Subtotal                    </td>
            <td class="last a-righttfoot">
                            <span class="price">$<%= grand_Total %></span>                    </td>
            </tr>
            <tr class="shipping">
            <td class="a-righttfoot" colspan="4">
                            Shipping &amp; Handling                    </td>
            <td class="last a-righttfoot">
                <%
                                        double d = 0;
                                           if(bdt.size()<4)
                                               d = 10;
                                           else if(bdt.size()>=4 && bdt.size()<8)
                                               d = 20;
                                           else if(bdt.size()>=8)    
                                               d = 50;
                                              
                %>
                <span class="price">$<%= d %></span>                    
            </td>
            </tr>
            <tr class="grand_total last">
            <td class="a-righttfoot" colspan="4">
                            <strong>Grand Total</strong>
                        </td>
            <td class="last a-righttfoot">
                            <strong><span class="price">$<%= grand_Total + d %></span></strong>
                        </td>
            </tr>
        </tfoot>
    </table>
<script type="text/javascript">decorateTable('my-orders-table', {'tbody' : ['odd', 'even'], 'tbody tr' : ['first', 'last']})</script>

                <div class="buttons-set">
                    <p class="back-link"><a href="<c:url value="/myaccountdashboard"/>"><small>« </small>Back to My Orders</a></p>
    </div>
</div>
    </div>
    <script type="text/javascript">
    //&lt;![CDATA[
        window.document.title ="View Order #<%= billid %>";
        
    //]]&gt;
    </script>
    <!-- end main content -->		
</div>